﻿#region

using System;
using System.IO;
using CDNSync.Providers;
using CDNSync.Providers.Impl;
using CDNSync.Providers.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace CDNSync.Test.Providers
{
    [TestClass]
    public class AmazonProviderClientTest
    {
        private const string AwsAccessKey = "";
        private const string AwsSecretKey = "";
        private const string BucketName = "";

        private IProviderClient providerClient;

        private void Authenticate()
        {
            providerClient.Authenticate(AwsAccessKey, AwsSecretKey); 
        }

        [TestInitialize]
        public void TestInit()
        {
            providerClient = new AmazonProviderClient();
        }

        [TestMethod]
        public void Authenticate_With_Invalid_AccessKey_Should_Return_False()
        {
            var actual = providerClient.Authenticate("baduser", "badpassword");

            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Authenticate_With_Invalid_SecretKey_Should_Return_False()
        {
            var actual = providerClient.Authenticate(AwsAccessKey, "badpassword");

            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Authenticate_With_Valid_Credentials_SecretKey_Should_Return_True()
        {
            var actual = providerClient.Authenticate(AwsAccessKey, AwsSecretKey);

            Assert.IsTrue(actual);
        }


        [TestMethod]
        public void BucketExists_With_ValidBucketName_Should_Return_True()
        {
            Authenticate(); 
            var actual = providerClient.BucketExists(BucketName);

            Assert.IsTrue(actual); 
        }

        [TestMethod]
        public void BucketExists_With_InValidBucketName_Should_Return_False()
        {
            Authenticate(); 
            var actual = providerClient.BucketExists(Guid.NewGuid().ToString());

            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void CreateBucket_In_Singapore_Should_Return_True()
        {
            Authenticate();

            var bucketName = Guid.NewGuid() + "-cdnsync";

            var actual = providerClient.CreateBucket(bucketName, BucketRegion.Singapore); 

            Assert.IsTrue(actual.WasSuccessful);

            var exists = providerClient.BucketExists(bucketName);

            Assert.IsTrue(exists); 
        }

        [DeploymentItem("bin\\Test.txt")]
        [TestMethod]
        public void Upload_Files_Should_Return_True()
        {
            Authenticate();

            var uploadFileRequest = new FileUploadRequest(new FileInfo("Test.txt").FullName, false, string.Empty, string.Empty, string.Empty, false);

            var actual = providerClient.Upload(new[] {uploadFileRequest}, BucketName); 

            Assert.IsTrue(actual.WasSuccessful);

        }

        [DeploymentItem("bin\\Test.txt")]
        [TestMethod]
        public void Upload_Files_With_GZip_Should_Return_True()
        {
            Authenticate();

            var uploadFileRequest = new FileUploadRequest(new FileInfo("Test.txt").FullName, false, string.Empty, string.Empty, string.Empty, true);

            var actual = providerClient.Upload(new[] { uploadFileRequest }, BucketName);

            Assert.IsTrue(actual.WasSuccessful);

        }

        //[TestMethod]
        //public void Create_Distribution_Should_Return_Dist_Url()
        //{
        //    Authenticate();


        //    var actual = providerClient.CreateDistribution(BucketName, null);
        //    Assert.IsTrue(actual.Contains("cloudfront.net")); 
                
         
        //}

        //[TestMethod]
        //public void DistributionExists_Should_Return_True()
        //{
        //    Authenticate();

        //    var actual = providerClient.DistributionExists(BucketName);

        //    Assert.IsTrue(actual); 


        //}



    }
}